/*
 * Router.h
 *
 *  Created on: Mar 13, 2011
 *      Author: kmueller
 */

#ifndef MAPROUTER_H_
#define MAPROUTER_H_

#include "Map.h"
#include "Road.h"

#include<map>

namespace opennav {

class Map;
class RouteSegment;
class Route;

class RoutingSettings {
public:
	enum PreferredRoute {
		FASTEST, SHORTEST
	};

	RoutingSettings();
	RoutingSettings(PreferredRoute preferred, bool avoidToll, bool avoidHighways);
	PreferredRoute get_preferred_route() const;
	bool is_avoid_toll() const;
	bool is_avoid_highways() const;

private:
	PreferredRoute preferred;
	bool avoidToll;
	bool avoidHighways;
};


class MapRouter {
	struct comparator {
		bool operator()(int a, int b) const {
			return a < b;
		}
	};

public:

	MapRouter(Map* r);
	void set_routing_settings(const RoutingSettings& s);
	int find(const RoadJunction& src, const RoadJunction& dst, Route& route);

private:
	typedef struct node {
		RoadJunction junction;
		const struct node* parent;
		RoadSegment viaSegment;
		int G, F;
		//		int k; //?
	} NodeInfo;

	int find(NodeInfo* src, const RoadJunction& dst, Route& route);
	std::multimap<int, MapRouter::NodeInfo*, comparator>::iterator findJunctionInList(
			std::multimap<int, NodeInfo*, comparator>& open, const NodeInfo* info) const;
	int assessment(const RoadSegment& segment);
	int heuristic(const RoadJunction& x, const RoadSegment& segment, const RoadJunction& dst);

	Map *reader;
	RoutingSettings settings;
};

}

#endif /* ROUTER_H_ */
